Ew. Internally force-match QStrings and C strings in GPX write version
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 15 Dec 2014 00:00:43 +0000 (00:00 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 15 Dec 2014 00:00:43 +0000 (00:00 +0000)
number to prevent leak.

gpsbabel/gpx.cc
gpsbabel/magproto.cc

index 52f105050b5eb1228d686c7fcc6bee86529adca0..5360134a0700e3b81a35fa8d0ab8774b05782c44 100644 (file)
@@ -1802,7 +1802,14 @@ gpx_write(void)
     if (gpx_version.isEmpty()) {
       gpx_wversion = (char*)"1.0";
     } else {
-      gpx_wversion = xstrdup(gpx_version);
+      // FIXME: this is gross.  The surrounding code is badly tortured by
+      // there being three concepts of "output version", each with a different
+      // data type (QString, int, char*).  This section needs a rethink. For
+      // now, we stuff over the QString gpx_version into the global char *
+      // gpx_wversion without making a malloc'ed copy.
+      static char tmp[16];
+      strncpy(tmp, CSTR(gpx_version), sizeof(tmp));
+      gpx_wversion = tmp;
     }
   }
 
index 2c9e11be55d6e97d5df58420cdd6c56e5cd0e76a..5161e5adfb49d7e3f064ca16ac8830a6b1b78500 100644 (file)
@@ -20,9 +20,6 @@
 
  */
 
-#include <math.h>
-#include <time.h>
-
 #include "defs.h"
 #include "magellan.h"
 #include "gbser.h"
@@ -33,6 +30,8 @@
 #endif
 #include <stdlib.h>
 #include <stdio.h>
+#include <math.h>
+#include <time.h>
 
 static int bitrate = 4800;
 static int wptcmtcnt;
@@ -1067,7 +1066,8 @@ mag_rteparse(char* rtemsg)
       rte_name = "Route";
       rte_name += QString::number(rtenum);
     } else {
-      rte_name = xstrndup(ca, ce - ca);
+      rte_name = ca;
+      rte_name.truncate(ce-ca);
     }
 
     n += ((ce - ca) + 1);